package com.ruoyi.project.user.kkidmapper.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.user.kkidmapper.domain.KkidMapper;
import com.ruoyi.project.user.kkidmapper.service.IKkidMapperService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * kkid映射Controller
 *
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/user/kkidmapper")
public class KkidMapperController extends BaseController {
    private String prefix = "user/kkidmapper";

    @Autowired
    private IKkidMapperService kkidMapperService;

    @RequiresPermissions("user:kkidmapper:view")
    @GetMapping()
    public String kkidmapper() {
        return prefix + "/kkidmapper";
    }

    /**
     * 新增kkid映射
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存kkid映射
     */
    @RequiresPermissions("user:kkidmapper:add")
    @Log(title = "kkid映射", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KkidMapper kkidMapper) {
        return toAjax(kkidMapperService.insertKkidMapper(kkidMapper));
    }

    /**
     * 修改kkid映射
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        KkidMapper kkidMapper = kkidMapperService.selectKkidMapperById(id);
        mmap.put("kkidMapper", kkidMapper);
        return prefix + "/edit";
    }

    /**
     * 修改保存kkid映射
     */
    @RequiresPermissions("user:kkidmapper:edit")
    @Log(title = "kkid映射", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KkidMapper kkidMapper) {
        return toAjax(kkidMapperService.updateKkidMapper(kkidMapper));
    }

    /**
     * 删除kkid映射
     */
    @RequiresPermissions("user:kkidmapper:remove")
    @Log(title = "kkid映射", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(kkidMapperService.deleteKkidMapperByIds(ids));
    }
}
